<?php

namespace App\Http\Controllers\OpenShop\Merchant;

use App\Http\Controllers\BaseController;
use App\Http\Middleware\OpenShop\MerchantAppAuth;
use App\Http\Validate\OpenShop\ShopLocation\OrderValidate;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Service\OpenShop\Merchant\OrderProgressService;
use App\Service\OpenShop\Merchant\OrderService;
use App\Service\OpenShop\User\RmsUserService;
use App\Service\OpenShop\Wap\SignOrderService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use function Symfony\Component\Translation\t;

class OrderController extends BaseController
{
    public function progress(Request $request)
    {
        $shopId  = (int)$request->header('shopId');
        $brandId = (int)$request->header('brandId');
        return $this->success((new OrderProgressService)->setShopId($shopId)->progress());
    }

    public function contract(Request $request)
    {
        $shopId  = (int)$request->header('shopId');
        return $this->success(OrderService::contractList($shopId));


    }

    public function detail(Request $request)
    {
        $shopId  = (int)$request->header('shopId');
        $brandId = (int)$request->header('brandId');
        return $this->success(OrderService::detail($shopId, $brandId));
    }

    /**
     * 支付记录
     *
     * @param Request $request
     * @return JsonResponse
     * @throws Exception
     */
    public function orderPayHistory(Request $request): JsonResponse
    {
        $shopId  = (int)$request->header('shopId');
       return $this->success(OrderService::orderPayHistory($shopId));
    }

    /**
     * 待支付订单列表
     * @param Request $request
     * @return JsonResponse
     */
    public function unpaidList(Request $request): JsonResponse
    {
        return $this->success(OrderService::unpaidLists(MerchantAppAuth::$userId));
    }

    /**
     * 设计费支付详情
     * @param Request $request
     * @return JsonResponse
     */
    public function payDesignDetail(Request $request): JsonResponse
    {
        $orderNo       = (string)$request->get('orderNo');
        $preparationNo = (string)$request->get('preparationNo');

        if (!$preparationNo) {
            return $this->fail(5, 'preparationNo不能为空');
        }

        $data = (new SignOrderService($orderNo, null, false))->payDesignDetail($preparationNo);
        return $this->success($data);
    }

    /**
     * 设计费支付详情
     * @param Request $request
     * @return JsonResponse
     */
    public function payDecorateDetail(Request $request): JsonResponse
    {
        return $this->fail(500, '此支付入口已废弃，请至订货订单页支付');

        $orderNo       = (string)$request->get('orderNo');
        $preparationNo = (string)$request->get('preparationNo');

        $data = (new SignOrderService($orderNo, null, false))->payDecorateDetail($preparationNo);
        return $this->success($data);
    }
}
